import { getAreaObj } from '@/utils/util'
import { getStore } from '@/utils/store'

export const tableConfig = () => {
	const userInfo = getStore('userInfo') || {}
	// 用户类型;1：大众用户，2：平台管理员，3：政务用户,4: 养老服务组织用户
	const classifyId = userInfo.classifyId

	const adminConfig = {
		stripe: true,
		border: true,
		maxHeight: '80vh',
		columns: [
			{
				label: '养老机构名称',
				prop: 'orgName',
			},
			{
				label: '星级',
				prop: 'organizationLevelLabel',
			},
			{
				label: '名称',
				prop: 'subsidyProjectName',
			},
			{
				label: '归属区域',
				prop: 'areas_name',
			},
			{
				label: '申请年份',
				prop: 'belongYear',
			},
			{
				label: '当前审批节点',
				prop: 'approvalStatusLabel',
			},
			{
				label: '审批状态',
				prop: 'approvalStatusSigle',
				custome: 'tag',
				dicData: [
					{ label: '驳回', value: '-1', style: { color: '#FA3E3E', background: '#FFC4B1' } },
					{ label: '待提交', value: 1, style: { color: '#FF8800', background: '#FFF3E5' } },
					{ label: '审批中', value: 2, style: { color: '#00A870', background: '#C8FFB1' } },
					{ label: '审批通过', value: 3, style: { color: '#0052D9', background: '#D9E8FF' } },
					{ label: '已录入发放凭证', value: 4, style: { color: '#7106C2', background: '#E9CBFF' } },
					{ label: '已录入回执', value: 5, style: { color: '#7106C2', background: '#E9CBFF' } },
				],
			},
			{
				label: '审批人',
				prop: 'approvalUser',
			},
			{
				label: '审批时间',
				prop: 'approvalTimes',
			},
			{
				label: '操作',
				prop: 'menu',
				width: 300,
				fixed: 'right',
			},
		],
	}
	const orgConfig = {
		stripe: true,
		border: true,
		maxHeight: '80vh',
		columns: [
			{
				label: '名称',
				prop: 'subsidyProjectName',
			},
			{
				label: '归属区域',
				prop: 'areas_name',
			},
			{
				label: '申请年份',
				prop: 'belongYear',
			},
			{
				label: '当前审批节点',
				prop: 'approvalStatusLabel',
			},
			{
				label: '审批状态',
				prop: 'approvalStatusSigle',
				custome: 'tag',
				dicData: [
					{ label: '驳回', value: '-1', style: { color: '#FA3E3E', background: '#FFC4B1' } },
					{ label: '待提交', value: 1, style: { color: '#FF8800', background: '#FFF3E5' } },
					{ label: '审批中', value: 2, style: { color: '#00A870', background: '#C8FFB1' } },
					{ label: '审批通过', value: 3, style: { color: '#0052D9', background: '#D9E8FF' } },
					{ label: '已录入发放凭证', value: 4, style: { color: '#7106C2', background: '#E9CBFF' } },
					{ label: '已录入回执', value: 5, style: { color: '#7106C2', background: '#E9CBFF' } },
				],
			},
			{
				label: '审批人',
				prop: 'approvalUser',
			},
			{
				label: '审批时间',
				prop: 'approvalTimes',
			},
			{
				label: '操作',
				prop: 'menu',
				width: 300,
				fixed: 'right',
			},
		],
	}
	return classifyId == 2 || classifyId == 3 ? adminConfig : orgConfig
}

export const baseConfig: any = {
	pageName: '审批管理',
	dictcodes: [],
	rowKey: 'id',
	tipName: 'name',
	exportMqTopic: '/ning/export/',
	api: {
		index: 'view_ofsSubsidyApply_submit',
		subsidy_report: 'view_downloadData_download',
	},
	auth: {
		index: 'view_ofsSubsidyApply_submit',
		mulitSet: 'mulitSet',
		subsidy_report: 'view_downloadData_download',
	},
	paramsObj: {
		isGrantList: false,
	},
	menuBtn: [
		{
			icon: '',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: '',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '90%',
	},
	searchConfig: {
		inline: true,
		labelPosition: 'right',
		labelWidth: '100px',
		column: [
			{
				label: '所属区域',
				prop: 'authAreas',
				type: 'AplidAreaSelect',
				span: 8,
			},
			{
				label: '申请时间',
				prop: 'createTimeBetween',
				type: 'dateBetween',
				span: 8,
				valueFormat: 'YYYY-MM-DD HH:mm:ss',
			},
			{
				label: '养老机构名称',
				prop: 'orgName',
				type: 'input',
				span: 8,
			},
			{
				label: '营业执照证号',
				prop: 'creditCode',
				type: 'input',
				span: 8,
			},
			// {
			// 	label: '审批状态',
			// 	prop: 'approvalStatus',
			// 	type: 'select',
			// 	span: 8,
			// 	dicData: [
			// 		{ label: '待提交', value: 1 },
			// 		{ label: '审批中', value: 2 },
			// 		{ label: '审批通过', value: 3 },
			// 		{ label: '驳回', value: 4 },
			// 	],
			// },
			{
				label: '审批人',
				prop: 'approvalUser',
				type: 'input',
				span: 8,
			},
		],
	},
	tableConfig: tableConfig(),
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areas_name = getAreaObj(item, '')
			if (item.approvalStatus && item.approvalStatus.length > 2) {
				const chart0 = item.approvalStatus.charAt(0)
				item.approvalStatusSigle = chart0 == '-' ? item.approvalStatus.substring(0, 2) : item.approvalStatus.substring(0, 1)
			} else {
				item.approvalStatusSigle = item.approvalStatus
			}
			return {
				...item,
				areas_name,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
}
